<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="showStore">显示仓库的内容</button>
        <h1>{{this.$store.state.counter}}</h1>
        <button @click="add">加1</button>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<!-- 1. 引入 vuex 依赖 -->
<script src="./node_modules/vuex/dist/vuex.js"></script>
<script>
    // 定义一个数据名称来代表那个数据名称，混淆视听
    let INCREMENT = "increment";

    let store = new Vuex.Store({

        state: {
            counter: 888
        },

        mutations: {
            //    对！他在这里用在这里，加中括号我也不知道为什么，管他呢，加就加
            [INCREMENT]: function (state, {
                payload
            }) {
                state.counter += payload.count;
            }
        }
    })
    // Vue.use(Vuex);
    let vm = new Vue({
        /* 3. 配置仓库 */
        store,
        el: "#app",
        methods: {
            showStore: function () {
                console.log(this.$store);
            },
            add: function () {
                // this.$store.commit(INCREMENT)  其实这样也可以
                this.$store.commit({
                    type: INCREMENT, //然后这里改成那个常量命，其实也就是传进去了
                    payload: {
                        count: 10
                    }
                })
            }
        },
    })
</script>

</html>